package com.dspot.declex.api.action.base;

import org.ohosannotations.api.builder.AbilityIntentBuilder;

import com.dspot.declex.annotation.action.StopOn;
import com.dspot.declex.api.action.runnable.OnAbilityResultRunnable;

public abstract class BaseAbilityActionHolder extends BaseActionHolder {

    protected OnAbilityResultRunnable OnResult;
    protected int requestCode;

    protected void init() {
    }

    protected void build(Runnable Done, OnAbilityResultRunnable OnResult) {
        super.build(Done);
        this.OnResult = OnResult;
    }

    protected void execute() {
        if (requestCode == 0) {
            intent().start();
        } else {
            intent().startForResult(requestCode);
        }
        if (Done != null) {
            Done.run();
        }
    }

    public BaseAbilityActionHolder withResult(int requestCode) {
        this.requestCode = requestCode;
        return this;
    }

    public BaseAbilityActionHolder withResult() {
        return this;
    }

    @StopOn("get")
    public abstract AbilityIntentBuilder<?> intent();

    protected OnAbilityResultRunnable getOnResult() {
        return OnResult;
    }

    protected int getRequestCode() {
        return requestCode;
    }

}
